package com.aerozhonghuan.logisticsmall.utils;

import android.text.TextUtils;

import java.util.HashMap;
import java.util.Map;

public class StatisticsConstant {

    private static StatisticsConstant statisticsConstant;

    public static StatisticsConstant getInstance() {
        if (statisticsConstant == null) {
            statisticsConstant = new StatisticsConstant();
        }
        return statisticsConstant;
    }

    public String INPUT_CONTENT = "";

    public enum ActionEvents {
        APP_INDEX, APP_START, APP_END, APP_VERSION, SYSTEM_VERSION, APP_INTERNER,
        LOGIN, LOGIN_OUT, APP_CHANNEL, CLICK_EVENT, NOTIFY_CLICK
    }

    public static Map<String, String> mapping = new HashMap<String, String>();

    static {
        mapping.put(ActionEvents.APP_INDEX.name(), "01");
        mapping.put(ActionEvents.APP_START.name(), "02");
        mapping.put(ActionEvents.APP_END.name(), "02");
        mapping.put(ActionEvents.APP_VERSION.name(), "03");
        mapping.put(ActionEvents.SYSTEM_VERSION.name(), "04");
        mapping.put(ActionEvents.APP_INTERNER.name(), "05");
        mapping.put(ActionEvents.LOGIN.name(), "06");
        mapping.put(ActionEvents.LOGIN_OUT.name(), "06");
        mapping.put(ActionEvents.APP_CHANNEL.name(), "07");
        mapping.put(ActionEvents.CLICK_EVENT.name(), "08");
        mapping.put(ActionEvents.NOTIFY_CLICK.name(), "09");
    }

    /**
     * clickHexType 点击类型转十六进制 2位
     * pageIndex 页面值
     * des  点击的id转十六进制  length位,没有id的字符串转十六进制
     */
    public void ClickActionParams(int clickType, int pageIndex, String des) {
        String clickHexType = Integer.toHexString(clickType);
        String pageIndexString = "0" + pageIndex;
        String hexDes = "";
        if (!TextUtils.isEmpty(des)) {
            hexDes = To16.bytesToHexString(des.getBytes());
        }
        clickHexType = CommunityTool.getInstance().addPosition(clickHexType, 2);
        String res = clickHexType + pageIndexString + hexDes;
        actionEvent(ActionEvents.CLICK_EVENT, res);
    }

    public String actionEvent(ActionEvents a, String param) {
        String TYPE = mapping.get(a.name());
        String time = CommunityTool.getInstance().getYesterdayTime("HHmmss");
        String msgHead = TYPE + time;
        //当TYPE为02时，param包含经纬度数据
        INPUT_CONTENT += msgHead + param + "\n";
        return INPUT_CONTENT;
    }


}
